#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>


float launch_tri(const char * type, int i)
{
	
	struct timeval tv1;
    struct timeval tv2;

	char * cmd = malloc(1024*sizeof(char));
	sprintf(cmd, "./%s %d", type, i);
	
    gettimeofday(&tv1, NULL);
    system(cmd);
    gettimeofday(&tv2, NULL);

    double seconds = ((tv2.tv_sec-tv1.tv_sec)*1000000 + (tv2.tv_usec-tv1.tv_usec));
	
	free(cmd);

	return seconds;
} 


int main()
{
	
	int size_min=1, size_max=100, i;
	
	FILE *file_tri, *file_ptri; 
	file_tri = fopen("curve_tri.csv", "w");
	file_ptri = fopen("curve_ptri.csv", "w");
	
	for(i=size_min; i<=size_max; i++)
	{
		fprintf(file_tri, "%f\n", launch_tri("tri", i));
		fprintf(file_ptri, "%f\n", launch_tri("ptri", i));
	}
	
	fclose(file_tri);
	fclose(file_ptri);

	return 0;
}
